package com.gxa.controller.GlmController;

import com.gxa.service.HomepageService;
import com.gxa.utils.R;
import com.gxa.vo.HomepageSubVo;
import com.gxa.vo.HotdepartVo;
import com.gxa.vo.HotdoctorVo;
import io.swagger.annotations.*;
import org.apache.commons.lang.time.DateUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.*;

@Api(tags = "首页查询模块")
@RestController
public class HomepageController {

    @Autowired
    private HomepageService homepageService;

    @ApiOperation(value="首页预约人数接口",notes="用于点击点击首页时渲染",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回预约人数的详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("cost:sel")
    @GetMapping("/homepage/queryNum")
    public R queryNum(){

        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        String format = sdf.format(new Date());
        Integer num = this.homepageService.queryNum(format+"%");

        return R.ok().put("data", num);
    }

    @ApiOperation(value="首页门诊充值总额接口",notes="用于点击首页时渲染",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回门诊充值总额的详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("cost:sel")
    @GetMapping("/homepage/queryNumre")
    public R queryNumre(){

        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        String format = sdf.format(new Date());
        Integer numre = this.homepageService.queryNumre(format+"%");

        return R.ok().put("data", numre);
    }

    @ApiOperation(value="首页门诊消费总额接口",notes="用于点击首页时渲染",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回门诊消费总额的详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("cost:sel")
    @GetMapping("/homepage/queryNumex")
    public R queryNumex(){

        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        String format = sdf.format(new Date());
        Integer numex = this.homepageService.queryNumex(format+"%");

        return R.ok().put("data", numex);
    }

    @ApiOperation(value="首页近七日预约情况接口",notes="用于点击首页时渲染",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回近七日预约人数的详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("cost:sel")
    @GetMapping("/homepage/queryNumlist")
    public R queryNumlist(){

        List<String> dateList = new ArrayList<>();
        List<Integer> numList = new ArrayList<>();
        Map map = new HashMap();
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");

        for(int i=0;i<7;i++) {
            Date date = DateUtils.addDays(new Date(),-i);
            String format = sdf.format(date);
            Integer num = this.homepageService.queryNumlist(format + "%");
            SimpleDateFormat sdf1=new SimpleDateFormat("MM月dd日");
            String newformat = sdf1.format(date);
            dateList.add(newformat);
            numList.add(num);
        }

        map.put("dateList",dateList);
        map.put("numList",numList);

        return R.ok().put("data", map);
    }

    @ApiOperation(value="首页近七日门诊充值情况接口",notes="用于点击首页时渲染",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回近七日门诊充值的详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("cost:sel")
    @GetMapping("/homepage/queryNumrelist")
    public R queryNumrelist(){

        List<String> dateList = new ArrayList<>();
        List<Integer> numList = new ArrayList<>();
        Map map = new HashMap();
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");

        for(int i=0;i<7;i++) {
            Date date = DateUtils.addDays(new Date(),-i);
            String format = sdf.format(date);
            Integer num = this.homepageService.queryNumrelist(format + "%");
            SimpleDateFormat sdf1=new SimpleDateFormat("MM月dd日");
            String newformat = sdf1.format(date);
            dateList.add(newformat);
            numList.add(num);
        }

        map.put("dateList",dateList);
        map.put("numList",numList);

        return R.ok().put("data", map);
    }

    @ApiOperation(value="首页实时挂号接口",notes="用于点击首页时渲染",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回实时挂号的详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("cost:sel")
    @GetMapping("/homepage/queryHomeSub")
    public R queryHomeSub(){

        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        String format = sdf.format(new Date());
        List<HomepageSubVo> homepageSubVos = this.homepageService.queryHomeSub(format+"%");

        System.out.println(homepageSubVos);
        return R.ok().put("data",homepageSubVos);
    }

    @ApiOperation(value="首页热门医生接口",notes="用于点击首页时渲染",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回热门医生的详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("cost:sel")
    @GetMapping("/homepage/queryHotdoctor")
    public R queryHotdoctor(){

        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        String format = sdf.format(new Date());
        List<HotdoctorVo> hotdoctorVos = this.homepageService.queryHotdoctor(format+"%");

        return R.ok().put("data",hotdoctorVos);
    }
    @ApiOperation(value="首页热门科室接口",notes="用于点击首页时渲染",produces = "application/json",response = R.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "Authorization", value = "令牌", paramType = "header",dataType ="String" ,required = true)
    })
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "返回热门科室的详细信息",examples = @Example(
                    value = {
                            @ExampleProperty(value = "{'code':200,'msg':'描述'}}", mediaType = "application/json")
                    })),
            @ApiResponse(code = 306, message = "登录已超时，请重新登录"),
            @ApiResponse(code = 307, message = "令牌格式不正确"),
            @ApiResponse(code = 401, message = "没有权限"),
            @ApiResponse(code = 403, message = "无效请求，本系统只支持AJAX请求"),
            @ApiResponse(code = 500, message = "服务器内部错误")
    })
    @RequiresPermissions("cost:sel")
    @GetMapping("/homepage/queryHotdepart")
    public R queryHotdepart(){

        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        String format = sdf.format(new Date());
        List<HotdepartVo> hotdepartVos = this.homepageService.queryHotdepart(format+"%");

        return R.ok().put("data",hotdepartVos);
    }

}
